web/src/pages/[...section].astro
277 lines · 7108 bytes
1---
2
3
4import Layout from '@layouts/Layout.astro';
5import Button from '@components/form/Button.astro';
6import Main from '@components/scafold/MainCard.astro';
7import ServiceList from '@components/things/ServiceList.astro';
8import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service';
9import { fetchData, slugify } from '@utils/fetch-data';
10import { parseMarkdown } from '@utils/parse-markdown';
11
12interface Props {
13 slug: string,
14 title: string,
15 services: Service[],
16 intro?: string,
17 notableMentions?: ShortService[] | string,
18 furtherInfo?: string,
19 wordOfWarning?: string,
20 alternativeTo?: string[];
21 categoryName: string,
22 otherSections: Section[],
23}
24
25const {
26 title, otherSections, services, notableMentions, furtherInfo, wordOfWarning,
27 alternativeTo, categoryName, intro,
28} = Astro.props;
29
30/**
31 * Make a list of keywords, for the <meta keywords> tag
32 */
33const makeKeyWordTag = () => {
34 const keywords = [];
35 keywords.push(`free and open source ${title} software`);
36 keywords.push(`private ${title} comparison`);
37 (alternativeTo || []).forEach((alt: string) => {
38 keywords.push(`privacy-respecting ${alt} alternative`);
39 keywords.push(`free open source ${alt} alternative`);
40 });
41 (services || []).forEach((serv: Service) => {
42 keywords.push(serv.name);
43 });
44 keywords.push('ad free');
45 keywords.push('open source software');
46 keywords.push('privacy respecting apps');
47 return keywords.join(', ');
48};
49
50/**
51 * Make a page title
52 */
53const makePageTitle = () => {
54 return `${title} | Awesome Privacy`;
55};
56
57/**
58 * Make a string page intro, for the description tag
59 */
60const makeDescriptionTag = () => {
61 let description = `A list of privacy respecting ${title}. `;
62 if (services && services.length > 0) {
63 const serviceList = services.map((serv: Service) => serv.name);
64 description += `Compare ${serviceList.join(', ')} and more private apps and services. `
65 } else {
66 description += `Find private apps and services. This section is still a work in progress. `;
67 }
68 description += 'All this, and much more at Awesome Privacy, '
69 description += 'the free and open source list of private software alternatives.';
70 return description;
71};
72
73export async function getStaticPaths() {
74 const pages = await fetchData().then((data) => {
75 const results: Array<Props> = [];
76 if (!data || !data.categories) return results;
77 (data as AwesomePrivacy).categories.forEach((category) => {
78 const sections = category.sections.map((section) => ({
79 slug: `${slugify(category.name)}/${slugify(section.name)}`,
80 title: section.name,
81 services: section.services,
82 intro: section.intro,
83 notableMentions: section.notableMentions,
84 furtherInfo: section.furtherInfo,
85 wordOfWarning: section.wordOfWarning,
86 alternativeTo: section.alternativeTo,
87 categoryName: category.name,
88 otherSections: category.sections,
89 }));
90 results.push(...sections);
91 });
92 return results;
93 });
94
95 return pages.map((props: Props) => {
96 return {params: { section: props.slug }, props };
97 });
98}
99
100const makePaginationLinks = () => {
101 const index = otherSections.findIndex(section => section.name === title);
102 const previousSection = index > 0 ? otherSections[index - 1].name : null;
103 const nextSection = index < otherSections.length - 1 ? otherSections[index + 1].name : null;
104 return { previous: previousSection, next: nextSection };
105};
106
107const { previous, next } = makePaginationLinks();
108
109---
110
111<Layout title={makePageTitle()} keywords={makeKeyWordTag()} description={makeDescriptionTag()} >
112 <Main>
113
114 <h2>{title}</h2>
115
116 {intro && (
117 <section class="intro">
118 <p set:html={parseMarkdown(intro)}></p>
119 </section>
120 )}
121
122 <ServiceList services={services} sectionName={title} categoryName={categoryName} />
123
124 {notableMentions && (
125 <section class="notable-mentions">
126 <h3>Notable Mentions</h3>
127 { Array.isArray(notableMentions) ?
128 <ul>
129 {notableMentions.map((mention) => (
130 <li>
131 <a href={mention.url}>{mention.name}</a>
132 {mention.description && (
133 <span>- </span>
134 <span set:html={parseMarkdown(mention.description)}></span>
135 )}
136 </li>
137 ))}
138 </ul> :
139 <p set:html={parseMarkdown(notableMentions)}></p>
140 }
141 </section>
142 )}
143
144 {furtherInfo && (
145 <section class="further-info">
146 <h3>Notes</h3>
147 <p set:html={parseMarkdown(furtherInfo)}></p>
148 </section>
149 )}
150
151 {wordOfWarning && (
152 <section class="word-of-warning">
153 <h3>Word of Warning</h3>
154 <p set:html={parseMarkdown(wordOfWarning)}></p>
155 </section>
156 )}
157
158 <div class="pagination-navigation">
159 { previous ? (
160 <Button url={`/${slugify(categoryName)}/${slugify(previous)}`}>
161 <span>← Previous</span>
162 <p>{previous}</p>
163 </Button>
164 ) : <p class="nothing"></p>}
165 <a href={`/${slugify(categoryName)}`} class="go-to-category">
166 View all in {categoryName} ({otherSections.length})
167 </a>
168 { next && (
169 <Button url={`/${slugify(categoryName)}/${slugify(next)}`}>
170 <span>Next →</span>
171 <p>{next}</p>
172 </Button>
173 )}
174 </div>
175 </Main>
176</Layout>
177
178<style lang="scss">
179
180section {
181 padding-bottom: 1rem;
182 &:not(:last-child) {
183 border-bottom: 2px solid var(--accent-3);
184 }
185}
186
187h2 {
188 font-size: 2rem;
189 margin: -2rem 0 2rem -2rem;
190 box-shadow: 6px 6px 0 var(--foreground);
191 background: var(--accent);
192 color: var(--accent-fg);
193 width: fit-content;
194 padding: 0.25rem 0.5rem;
195 }
196
197.pagination-navigation {
198 display: flex;
199 justify-content: space-between;
200 align-items: center;
201 padding: 1rem 0;
202 :global(.button) {
203 min-width: 120px;
204 width: fit-content;
205 padding: 0.25rem 1rem;
206 text-align: right;
207 &:first-child { text-align: left; }
208 p {
209 margin: 0;
210 font-weight: normal;
211 font-size: 1rem;
212 }
213 span {
214 font-size: 0.8rem;
215 }
216
217 }
218 .nothing {
219 width: 120px;
220 }
221 .go-to-category {
222 color: var(--foreground);
223 font-size: 0.8rem;
224 opacity: 0.5;
225 @media (max-width: 768px) {
226 display: none;
227 }
228 }
229}
230
231.intro {
232 font-style: italic;
233 opacity: 0.7;
234}
235
236
237.further-info, .notable-mentions, .word-of-warning {
238 h3 {
239 font-size: 1.4rem;
240 margin: 1rem 0;
241 }
242 :global(p) {
243 font-size: 0.9rem;
244 opacity: 0.7;
245 :global(strong) {
246 font-weight: 500;
247 }
248 :global(a) {
249 color: var(--foreground);
250 transition: all 0.15s ease-in-out;
251 &:hover {
252 color: var(--accent);
253 }
254 }
255 }
256 :global(strong) {
257 font-weight: 500;
258 }
259 :global(h4) {
260 font-size: 1.2rem;
261 margin: 0.5rem 0 0 0;
262 }
263 :global(ul) {
264 list-style: circle;
265 padding-left: 1rem;
266 font-size: 0.9rem;
267 opacity: 0.7;
268 li {
269 margin-bottom: 0.25rem;
270 :global(p) {
271 display: inline;
272 }
273 }
274 }
275}
276
277</style>